﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    class DbHelper
    {

        public readonly static string comString = "server =PC-202001311751\\MYSQLSERVER; uid =yun0823;pwd =jxy130452;database =WinformText";
        public static DataTable GetdataTable(string sql)
        {
           
            SqlConnection sqlConnection = new SqlConnection(comString);
            string codString = sql;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(codString, sqlConnection);
            DataTable dataTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(dataTable);
            return dataTable;
        }

        public static int AddOrEditSave(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(comString);
            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
            sqlConnection.Open();
            return sqlCommand.ExecuteNonQuery();
        }

    }
}
